package com.zhu.day.controller;

import redis.clients.jedis.Jedis;

public class LuaText {
    /*
     *查:roundNo=1; 传参:1 如果相等则:inc,否则:return roundNo;
     * 生成
     */
    public static final String roundLua = "" +
            "local roundNo = ARGV[1];" +
            "local lastRoundNo = ARGV[2];" +
            "local key = KEYS[1];" +
            "local curRoundNo = redis.call('get',key);" +
            "if(curRoundNo ~= false and curRoundNo ~= nil and tonumber(roundNo) == tonumber(curRoundNo)) then " +
            "local curN = redis.call('incrby',key,1);" +
            "return -3;" +
            "end;"+
            "if(curN ~= false and curN ~= nil and tonumber(curN) > tonumber(lastRoundNo)) then " +
            "local curN2 = redis.call('set',key,-1);" +
            "return -1;" +
            "end;"+
            "local curRoundNo2 = redis.call('get',key);" +
            "return curRoundNo2";


    public static final String addition = "" +
            "local key = KEYS[1];"+
            "local curTime = tonumber(ARGV[1]);"+
            "local additionTime = tonumber(ARGV[2]);"+
            "local curVal = redis.call('get',key);"+
            "if(curVal == false or curVal == nil or (tonumber(curVal) < curTime)) then "+
            "redis.call('set',key,curTime+additionTime);"+
            "return '1'"+
            "end;"+
            "redis.call('set',key,tonumber(curVal)+additionTime)"+
            "return '1'";

    public static void main(String[] args) {
//        Jedis jedis = new Jedis();
//        String starid = "12345";
//        Integer taskNo = 1;
//        Integer roundNo = 1;
//        String lastRoundNo = "3";
//
//        String STAR_TASK_ROUND_NO = "lucky:dare:2021:star:%s:taskNo:%s:round:no:sign:%s";
//        String key = String.format(STAR_TASK_ROUND_NO, starid, taskNo, "signXx");
//        System.out.println("key:" + key);
//        String set = jedis.get(key);
//        System.out.println("get:" + set);
//
////        jedis.set(key,"1");
//        String sha = jedis.scriptLoad(roundLua);
//        Object obj = jedis.evalsha(sha, 1, key, roundNo.toString(),lastRoundNo);
//        System.out.println(obj);
//        String get
//                = jedis.get(key);
//        System.out.println("get:" + get);


        Double a =1.631090416506E12;
        long b = a.longValue();
        System.out.println(b);

    }

}
